package com.syni.mdd.yhd.common.all.utils;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.sjb.common.component.utils.common.utils.AppConfig;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.vod.v20180717.VodClient;
import com.tencentcloudapi.vod.v20180717.models.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
public class TCCloudUtils {

    private static final Logger log = LogManager.getLogger(TCCloudUtils.class);

    private static Credential cred;

    private static HttpProfile httpProfile;

    private static ClientProfile clientProfile;

    private static VodClient client;

    static  {
        if (cred == null) {
            cred = new Credential(AppConfig.getProperty("cloud.secret.id"), AppConfig.getProperty("cloud.secret.key"));
//        cred = new Credential("AKIDRPa3fLnQg9vmFcLxgfdCh4753V1iQqOT","93rblR5scM7ub8Xtt7D85vb7Vknk3EHH");
//        cred = new Credential("AKID74mGUTJk13wa0APmFUVHp9E7l9H977F8","nLeiYAXfZEepqdDdqyub3II4bsuhDTTD");
            httpProfile = new HttpProfile();
            httpProfile.setEndpoint("vod.tencentcloudapi.com");
            clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            client = new VodClient(cred, "ap-guangzhou", clientProfile);
        }
    }

    public static ProcessMediaResponse videoDealTask(String fileId) {
        Long[] definitionArray = {10L, 20L, 30L};
        TranscodeTaskInput[] transcodeTaskInputArray = new TranscodeTaskInput[definitionArray.length];
        for (int i = 0; transcodeTaskInputArray.length > i; i++) {
            transcodeTaskInputArray[i] = new TranscodeTaskInput();
            transcodeTaskInputArray[i].setDefinition(definitionArray[i]);
        }
        CoverBySnapshotTaskInput[] coverBySnapshotTaskInput = {new CoverBySnapshotTaskInput()};
        coverBySnapshotTaskInput[0].setDefinition(10L);
        coverBySnapshotTaskInput[0].setPositionType("Time");
        coverBySnapshotTaskInput[0].setPositionValue(3.0F);
        MediaProcessTaskInput mediaProcessTaskInput = new MediaProcessTaskInput();
        mediaProcessTaskInput.setTranscodeTaskSet(transcodeTaskInputArray);
        mediaProcessTaskInput.setCoverBySnapshotTaskSet(coverBySnapshotTaskInput);


        AdaptiveDynamicStreamingTaskInput adaptiveDynamicStreamingTaskInput = new AdaptiveDynamicStreamingTaskInput();
        ProcessMediaRequest processMediaRequest = new ProcessMediaRequest();
        processMediaRequest.setMediaProcessTask(mediaProcessTaskInput);
        processMediaRequest.setFileId(fileId);
        ProcessMediaResponse processMediaResponse = null;
        SampleSnapshotTaskInput[] sampleSnapshotTaskInputArray = {new SampleSnapshotTaskInput()};
        sampleSnapshotTaskInputArray[0].setDefinition(20176L);
        mediaProcessTaskInput.setSampleSnapshotTaskSet(sampleSnapshotTaskInputArray);
        try {
            log.info(" 开始视频处理请求 FileId : " + fileId);
            processMediaResponse = client.ProcessMedia(processMediaRequest);
        } catch (Exception e) {
            log.error("exception:", e);
        }
        return processMediaResponse;
    }

    public static ProcessMediaResponse videoEncryption(String fileId) {
        Long[] definitionArray = {10L, 20L, 30L};
        TranscodeTaskInput[] transcodeTaskInputArray = new TranscodeTaskInput[definitionArray.length];
        for (int i = 0; transcodeTaskInputArray.length > i; i++) {
            transcodeTaskInputArray[i] = new TranscodeTaskInput();
            transcodeTaskInputArray[i].setDefinition(definitionArray[i]);
        }
        CoverBySnapshotTaskInput[] coverBySnapshotTaskInput = {new CoverBySnapshotTaskInput()};
        coverBySnapshotTaskInput[0].setDefinition(10L);
        coverBySnapshotTaskInput[0].setPositionType("Time");
        coverBySnapshotTaskInput[0].setPositionValue(3.0F);
        MediaProcessTaskInput mediaProcessTaskInput = new MediaProcessTaskInput();
        mediaProcessTaskInput.setTranscodeTaskSet(transcodeTaskInputArray);
        mediaProcessTaskInput.setCoverBySnapshotTaskSet(coverBySnapshotTaskInput);
        ProcessMediaRequest processMediaRequest = new ProcessMediaRequest();
        processMediaRequest.setMediaProcessTask(mediaProcessTaskInput);
        processMediaRequest.setFileId(fileId);
        ProcessMediaResponse processMediaResponse = null;
        SampleSnapshotTaskInput[] sampleSnapshotTaskInputArray = {new SampleSnapshotTaskInput()};
        sampleSnapshotTaskInputArray[0].setDefinition(20176L);
        mediaProcessTaskInput.setSampleSnapshotTaskSet(sampleSnapshotTaskInputArray);
        try {
            log.info(" 开始视频处理请求 FileId : " + fileId);
            processMediaResponse = client.ProcessMedia(processMediaRequest);
        } catch (Exception e) {
            log.error("exception:", e);
        }
        return processMediaResponse;
    }


    public static ProcessMediaResponse videoReview(String fileId) {
        AiContentReviewTaskInput aiContentReviewTaskInput = new AiContentReviewTaskInput();
        aiContentReviewTaskInput.setDefinition(20L);
        ProcessMediaRequest processMediaRequest = new ProcessMediaRequest();
        processMediaRequest.setAiContentReviewTask(aiContentReviewTaskInput);
        processMediaRequest.setFileId(fileId);
        ProcessMediaResponse processMediaResponse = null;
        try {
            log.info(" 开始视频处理请求 FileId : " + fileId);
            processMediaResponse = client.ProcessMedia(processMediaRequest);
        } catch (Exception e) {
            log.error("exception:", e);
        }
        return processMediaResponse;
    }


    public static ProcessMediaResponse videoAnalysis(String field) {
        AiAnalysisTaskInput aiAnalysisTaskInput = new AiAnalysisTaskInput();
        aiAnalysisTaskInput.setDefinition(10L);
        ProcessMediaRequest processMediaRequest = new ProcessMediaRequest();
        processMediaRequest.setAiAnalysisTask(aiAnalysisTaskInput);
        processMediaRequest.setFileId(field);
        ProcessMediaResponse processMediaResponse = null;
        try {
            log.info(" 开始视频处理请求 FileId : " + field);
            processMediaResponse = client.ProcessMedia(processMediaRequest);
        } catch (Exception e) {
            log.error("exception:", e);
        }
        return processMediaResponse;

    }


    public static void commmitVideoTask(String fileId){
        Long[] definitionArray = {30L,47085L};
        TranscodeTaskInput[] transcodeTaskInputArray = new TranscodeTaskInput[definitionArray.length];
        for (int i = 0; transcodeTaskInputArray.length > i; i++) {
            transcodeTaskInputArray[i] = new TranscodeTaskInput();
            transcodeTaskInputArray[i].setDefinition(definitionArray[i]);
        }
        MediaProcessTaskInput mediaProcessTaskInput = new MediaProcessTaskInput();
        mediaProcessTaskInput.setTranscodeTaskSet(transcodeTaskInputArray);
        ProcessMediaRequest processMediaRequest = new ProcessMediaRequest();
        processMediaRequest.setMediaProcessTask(mediaProcessTaskInput);
        processMediaRequest.setFileId(fileId);
        ProcessMediaResponse processMediaResponse = null;
        try {
            log.info(" 开始视频处理请求 FileId : " + fileId);
            processMediaResponse = client.ProcessMedia(processMediaRequest);
            System.out.println("回调数据 ：" + JSON.toJSONString(processMediaResponse));
        } catch (Exception e) {
            log.error("exception:", e);
        }
    }

    public static void commmitVideoTurnAutoCodeTask(String fileId){
        Long[] definitionArray = {10L};
        AdaptiveDynamicStreamingTaskInput[] adaptiveDynamicStreamingTaskInputs = new AdaptiveDynamicStreamingTaskInput[definitionArray.length];
        for (int i = 0; adaptiveDynamicStreamingTaskInputs.length > i; i++) {
            adaptiveDynamicStreamingTaskInputs[i] = new AdaptiveDynamicStreamingTaskInput();
            adaptiveDynamicStreamingTaskInputs[i].setDefinition(definitionArray[i]);
        }
        MediaProcessTaskInput mediaProcessTaskInput = new MediaProcessTaskInput();
        mediaProcessTaskInput.setAdaptiveDynamicStreamingTaskSet(adaptiveDynamicStreamingTaskInputs);
        ProcessMediaRequest processMediaRequest = new ProcessMediaRequest();
        processMediaRequest.setMediaProcessTask(mediaProcessTaskInput);
        processMediaRequest.setFileId(fileId);
        ProcessMediaResponse processMediaResponse = null;
        try {
            log.info(" 开始视频处理请求 FileId : " + fileId);
            processMediaResponse = client.ProcessMedia(processMediaRequest);
            System.out.println("回调数据 ：" + JSON.toJSONString(processMediaResponse));
        } catch (Exception e) {
            log.error("exception:", e);
        }
    }


    public static void craeteHLSEncryptionTemplate(){

    }
}


